import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:zyll_book/app/searchAppBar.dart';
import 'package:zyll_book/message/send_messsage_screen.dart';

import 'bubble.dart';
import 'custom_shape.dart';
import 'received_message_screen.dart';
import 'received_message_screen2.dart';

class MyChatPage extends StatefulWidget {
  const MyChatPage({Key? key}) : super(key: key);

  @override
  State<MyChatPage> createState() => _myChatPageWidgetState();
}

class _myChatPageWidgetState extends State<MyChatPage> {


  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(45),
        child: AppBar(
            leading: BackButton(color: Colors.black,),
            backgroundColor: Colors.grey.shade300,
            title: Text('消息', style: TextStyle(letterSpacing: 1,fontWeight: FontWeight.w500,fontSize: 20,color: Colors.black),),
            centerTitle: true,
            actions: <Widget>[
              IconButton(
                icon: const Icon(Icons.more_vert,color: Colors.black,),
                tooltip: '菜单',
                onPressed: () {
                  ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('菜单'),duration: Duration(seconds: 1)));
                  // _counterRoute.present('搜索');
                },
              ),
            ]
        ),
      ),
      body: new ListView.builder(
        itemCount: 10,
        itemBuilder: (BuildContext context, int index) {
          return GestureDetector(
            behavior: HitTestBehavior.opaque,
            child:
            Stack(
              // direction: Axis.horizontal,
              children: [
                Padding(
                  padding: EdgeInsets.fromLTRB(0, 5, 0, 0),
                  child: Align(
                    // alignment: FractionalOffset(0.01,0),左边
                    alignment: FractionalOffset(index ==1? 0.99:0.01,0),
                    child: Container(
                      height: 50.0, //容器高度
                      width: 50.0, //容器宽度
                      decoration: BoxDecoration(
                        //装饰线
                          color: Colors.blue[600], //颜色
                          // border: Border.all(
                          //   //边框
                          //   //color: Colors.deepOrange,
                          //     width: 1.0),
                          borderRadius: BorderRadius.all(
                            //边框半径
                            Radius.circular(10), //圆形
                          ),
                          image: DecorationImage(
                            image: NetworkImage(
                              'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2F76%2F7b%2F57%2F767b578c5e68a890cf98b5b7e002aca8.jpeg',
                            ),
                            fit: BoxFit.cover,
                            repeat: ImageRepeat.noRepeat, //平铺模式
                          )),
                    ),

                  ),
                ),

                Padding(
                    padding: EdgeInsets.fromLTRB(55, 5, 55, 20),
                    child: Align(
                      alignment: FractionalOffset(index ==1? 0.99:0.01,0),
                      child: Text("武则天1"),
                    )
                ),


                Padding(
                    padding: index == 1?EdgeInsets.fromLTRB(650, 28, 55, 20):EdgeInsets.fromLTRB(69, 28, 55, 20),
                    child: Bubble(
                      constraints: BoxConstraints(
                        maxWidth: 320.0,
                      ),
                      direction: index ==1?BubbleDirection.right:BubbleDirection.left,
                      color: Colors.orangeAccent,
                      padding: EdgeInsets.fromLTRB(10.0, 5.0, 7.0, 5.0),
                      // decoration: null,
                      // margin: null,
                      // alignment: null,
                      // borderRadius: null,
                      child: Text(
                        "这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息这是一个右边的信息",
                        style: TextStyle(color: Colors.white),
                      ),
                    )),

              ],
            ),

          );
        },
      ),

        // SnackBar
    );// TODO: implement build

    // return  ;
  }

}
